package com.guoxue.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.guoxue.dao.ITapesRecordsDao;
import com.guoxue.domain.TapesRecordsVo;
import com.guoxue.domain.TapesShareVo;
@Repository
public class TapesRecordsDaoImpl extends BaseDaoImpl<TapesRecordsVo> implements ITapesRecordsDao {

	@Override
	public void saveTapesRecords(TapesRecordsVo tr) {
		saveOrUpdate(tr);
	}
	
	public void deleteByTimeAndStatus(String date) {
		executeHql("DELETE FROM TapesRecordsVo t WHERE t.sysflag=1 AND t.deleteTime<?", new Object[] {date});
	}
	
	public List<TapesRecordsVo> findByTimeAndStatus(String date) {
		return find("FROM TapesRecordsVo t WHERE t.sysflag=1 AND t.deleteTime<?",new Object[] {date});
	}

	@Override
	public List<TapesRecordsVo> findByUidAndStatus(int uid, int sysflag) {
		return find("FROM TapesRecordsVo t WHERE t.uid=? AND t.sysflag=? ORDER BY t.commitTime DESC",new Object[] {uid,sysflag});
	}
	
	@Override
	public Long getTapesRecordsTotal(int uid,String flag) {
		return count("SELECT count(*) FROM TapesRecordsVo t WHERE t.uid = ? AND t.tapes = ? AND t.sysflag=0",new Object[] {uid,flag});
	}

	@Override
	public TapesRecordsVo getTapesById(int tapesId) {
		return get("FROM TapesRecordsVo t WHERE t.id=? AND t.sysflag=0", new Object[] {tapesId});
	}

	@Override
	public TapesRecordsVo getTapesByChapterAndUid(String chapter, Integer uid) {
		return get("FROM TapesRecordsVo t WHERE t.chapter=? AND t.uid=? AND t.sysflag=0", new Object[] {chapter,uid});
	}

	@Override
	public int getTapesCounts(Integer uid) {
		int num = count("SELECT count(*) FROM TapesRecordsVo t WHERE t.uid = ? AND t.sysflag=0",new Object[] {uid}).intValue();
		return num;
	}

	
}
